class_name InputActionChecker
extends Node
## Input Action Checker
## Version: 0.1.0

#region Signals
##
signal pressed(current_time: float)

##
signal double_click_started(current_time: float)

##
signal single_click_started(current_time: float)

##
signal released(current_time: float)

##
signal long_pressed(current_time: float)
#endregion

##
@export var action_name: String = ""

##
var _double_click_threshold: float = 0.2

##
var _long_pressed_threshold: float = 0.2

##
var _last_press_start_time: float = 0.0


func _ready() -> void:
	assert(action_name != "", "Action name must be set!")


func on_update(_delta: float) -> void:
	var current_time: float = Time.get_ticks_msec() / 1000.0

	if Input.is_action_just_pressed(action_name):
		if current_time - _last_press_start_time < _double_click_threshold:
			double_click_started.emit(current_time)
		else:
			single_click_started.emit(current_time)
		_last_press_start_time = current_time
	
	if Input.is_action_pressed(action_name):
		pressed.emit(current_time)
		if current_time - _last_press_start_time > _long_pressed_threshold:
			long_pressed.emit(current_time)

	if Input.is_action_just_released(action_name):
		released.emit(current_time)
